<?php
namespace Home\Controller;
use Think\Controller;
/**
* 用户相关控制器
*/
class UserController extends Controller{
	public function index(){
		$this->display();
	}
 
	/**
	*  发现
	*/
	public function lists(){
		$user_id = get_user();

		// 1 活跃  2最近
		$type = I('post.type');
 
		// 性别 1表示男 2表示女 0不限
		$sex = I('post.sex');

		$page_no = I('post.page') ? I('post.page') : 1;

		$lng = I('post.lng') ? I('post.lng') : 1; //经度
		$lat = I('post.lat') ? I('post.lat') : 1; //维度

		if ($type==1) 
		{
			$order = 'login_time desc';
		}
		if ($type==2) 
		{
			$order = "ACOS(SIN((".$lat." * 3.1415) / 180 ) *SIN((lat * 3.1415) / 180 ) +COS((".$lat." * 3.1415) / 180 ) * COS((lat * 3.1415) / 180 ) *COS((".$lng." * 3.1415) / 180 - (lng * 3.1415) / 180 ) ) * 6380 asc";
		}
		if ($sex==2) 
		{
			$map['sex'] = 2;
		}
		if ($sex==1) 
		{
			$map['sex'] = 1;
		}
		//过滤被拉黑的人
		$bl_ids = M('black')->where('user_id='.$user_id)->getField("bl_user_id",true);
		if(count($bl_ids)>0 ){
			if(count($bl_ids) == 1){
				$bl_ids[1] = $user_id;
				$map['id'] = array('not in',$bl_ids);
			}else{
				$bl_ids[] = $user_id;
				$map['id'] = array('not in',$bl_ids);
			}
		}else{
			$map['id'] = array('neq',$user_id);
		}
		//认证的用户才显示在玩伴列表
		$map['is_verify'] = 1;

		$map['photo_id'] = array('exp', 'IS NOT NULL');
		$map['photo_ok'] = 1;
		$map['id'] = array('neq',3);
		$data = M('user')->page($page_no,10)
			->where($map)
			->field("id,username,sex,age,star,add_time,login_time,is_verify,photo_id,lng,lat")
			->order($order)
			->select();


		$relations = M('follow')->where('user_id='.$user_id)->getField('fo_user_id',true);
        $list = array();
		foreach ($data as $key => $value) {
			if (!$value['photo_id'] || stristr($value['photo_id'],'wx.qlogo')) {
				continue;
			}
			$oneData = $value;
			$oneData['add_time'] = getIntervalTime($value['login_time']);
			$oneData['km'] = getdistance($lng,$lat,$value["lng"],$value["lat"]);
			$oneData['age'] = $value['age'] ? $value['age'] : "未知";

			if (in_array($value['id'], $relations)) {
				$oneData['is_friend'] = 1;
			}else{
				$oneData['is_friend'] = 0;
			}
			$list[] = $oneData;
		}

		$result['status'] = 1;
		$result['self_id'] = $user_id;
		$result['message'] = "请求成功";
		$result['list'] = $list;

		$this->ajaxReturn($result);
	}

	/**
	* 照片
	*/
	public function getPhotos(){
		$user_id = I('post.user_id') ? I('post.user_id') : $this->ajaxReturn(is_not('user_id/必须'));

		$photos = M('photos')->field("photo_id")->where('user_id='.$user_id)->select();
		$user = M('user')->where('id='.$user_id)->field('is_verify')->getField('is_verify');
		foreach ($photos as $key => $value) {
			$photos[$key]['is_verify']=$user;
		}
		$result['status'] = 1;
		$result['message'] = "请求成功";
		$result['list'] = $photos;

		$this->ajaxReturn($result);
	}

	/**
	* 详情
	*/
	public function detail(){
		$user_id = I('post.user_id') ? I('post.user_id') : $this->ajaxReturn(is_not('user_id/必须'));
		$id = get_user();
		$data = M('user a')
			->field("a.id,a.username,a.sex,a.age,a.star,a.introduction,a.city,a.job,a.photo_id,a.is_verify,a.label,a.helloword,a.voice_id,a.voice_status,a.body_shape")//,b.fail_join as times,b.timeKeeping,b.open,b.chat,b.late,b.pride,b.communication
			//->join('left join zm_impress b on a.id=b.user_id')
			->where('a.id='.$user_id)->find();
		$times1 = M('activity')->where(array('user_id'=>$user_id,'status'=>11))->count();
		$times2 = M('activity_log')->where(array('user_id'=>$user_id,'status'=>18))->count();
		$data['times'] = intval($times1)+intval($times2);
		$goodArray = array();
		$badArray = array();			
		if(1 == $data['sex']){
			$goodwhere = array(
				'sex' => array('neq',2),
				'type'=> 1
			);
			$badwhere = array(
				'sex' => array('neq',2),
				'type'=> 2
			);
			$good_contents = M('comment_content')->where($goodwhere)->getField('content',true);
			$bad_contents = M('comment_content')->where($badwhere)->getField('content',true);
			
		}else{
			$goodwhere = array(
				'sex' => array('neq',1),
				'type'=> 1
			);
			$badwhere = array(
				'sex' => array('neq',1),
				'type'=> 2
			);
			$good_contents = M('comment_content')->where($goodwhere)->getField('content',true);
			$bad_contents = M('comment_content')->where($badwhere)->getField('content',true);
			
		}
		foreach ($good_contents as $value) {
			$goodArray[$value] = 0;
		}
		foreach ($bad_contents as $value) {
			$badArray[$value] = 0;
		}

		$comments = M('comment')->where(array('to_user_id'=>$user_id))->select();
		
		$like_count = 0;
		$not_count = 0;
		foreach ($comments as $key_c => $value_c) {
			$like = $value_c['like'];
			if(!empty($like)){
				$likeArr = explode(',', $like);
				foreach ($likeArr as $like_v) {
					if(array_key_exists($like_v, $goodArray)){
						$goodArray[$like_v] = $goodArray[$like_v] + 1;
						$like_count = $like_count + 1;
					}
				}
			}
			
			$not_like = $value_c['not_like'];

			if(!empty($not_like)){
				$notArray = explode(',', $not_like);

				foreach ($notArray as $not_v) {
					if(array_key_exists($not_v, $badArray)){
						$badArray[$not_v] = $badArray[$not_v] + 1;
						$not_count = $not_count + 1;
					}
				}
			}
		}
		$com_conut = $like_count + $not_count;
		if($like_count > 0){
			foreach ($goodArray as $good_k => $good_v) {
				$tmp = array(
					'text' => $good_k,
					'score'=> intval($good_v*100/$com_conut) 
				);
				$data['good'][] = $tmp;
			}
		}else{
			foreach ($goodArray as $good_k => $good_v) {
				$tmp = array(
					'text' => $good_k,
					'score'=> 0 
				);
				$data['good'][] = $tmp;
			}
		}

		if($not_count > 0){
			foreach ($badArray as $bad_k => $bad_v) {
				$tmp = array(
					'text' => $bad_k,
					'score'=>intval($bad_v*100/$com_conut)
				);
				$data['bad'][] = $tmp;
			}
		}else{
			foreach ($badArray as $bad_k => $bad_v) {
				$tmp = array(
					'text' => $bad_k,
					'score'=> 0
				);
				$data['bad'][] = $tmp; 
			}
		}
		
		//判断语音有没有审核通过
		if ($data['voice_status']!=1) 
		{
			$data['voice_id'] = '';
		}
		$data['is_friend'] = M('follow')->where(array('user_id'=>$id,'fo_user_id'=>$user_id))->find() ? 1 :0 ;
		$data['is_black'] = M('black')->where(array('user_id'=>$id,'bl_user_id'=>$user_id))->find() ? 1 :0 ;
		$data['label'] = explode(",", $data['label']);
		$result['status'] = 1;
		$result['message'] = "请求成功";
		$result['list'] = $data;

		$this->ajaxReturn($result);
	}

	/**
	* 关注
	*/
	public function follow(){
		//关注人id
		$user_id = get_user();//I('post.user_id') ? I('post.user_id') : $this->ajaxReturn(is_not('user_id/必须'));
		$user = M('user')->where('id='.$user_id)->find();

		if(0 == $user['is_verify']){
			$result["result"] = false;
			$result["message"] = '请先认证';
			return $result;
		}
		
		//被关注人id
		$fo_user_id = I('post.fo_user_id') ? I('post.fo_user_id') : $this->ajaxReturn(is_not('fo_user_id/必须'));

		$list = array(
			'user_id'   =>$user_id,
			'fo_user_id'=>$fo_user_id,
			'add_time'  =>time(),
			);

		$data = M('follow')->add($list);

		if ($data) 
		{	
			$result["result"] = true;
			$result['message'] = "提交成功";
			$result['list'] = $data;
			$this->ajaxReturn($result);
		}else
		{
			$result["result"] = false;
        	$result["message"] = '关注失败';
        	$this->ajaxReturn($result);
		}
	}

	/**
	* 取消关注
	*/
	public function noFollow(){
		$user_id = get_user();

		$fo_user_id = I('post.fo_user_id') ? I('post.fo_user_id') : $this->ajaxReturn(is_not('fo_user_id/必须'));

		$data = M('follow')->where(array('user_id'=>$user_id,'fo_user_id'=>$fo_user_id))->delete();

		if ($data) 
		{	
			$result["result"] = true;
			$result['message'] = '已经取消关注';
			$result['list'] = $data;
			$this->ajaxReturn($result);
		}else
		{
			$result["result"] = false;
        	$result["message"] = '取消失败';
        	$this->ajaxReturn($result);
		}
	}

	/**
	* 拉黑名单
	*/
	public function blacklist(){
		//id
		$user_id = get_user();//I('post.user_id') ? I('post.user_id') : $this->ajaxReturn(is_not('user_id/必须'));
		$user = M('user')->where('id='.$user_id)->find();

		if(0 == $user['is_verify']){
			$result["result"] = false;
			$result["message"] = '请先认证';
			return $result;
		}
		//被拉黑的人
		$bl_user_id = I('post.bl_user_id') ? I('post.bl_user_id') : $this->ajaxReturn(is_not('bl_user_id/必须'));

		if ($user_id == $bl_user_id) 
		{
			$this->ajaxReturn(is_not('不能拉黑自己！'));
		}

		$list = array(
			'user_id'   =>$user_id,
			'bl_user_id'=>$bl_user_id,
			'add_time'  =>time(),
			);

		$data = M('black')->add($list);

		if ($data) 
		{	
			$result["result"] = true;
			$result['message'] = "提交成功";
			$result['list'] = $data;
			$this->ajaxReturn($result);
		}else
		{
			$result["result"] = false;
        	$result["message"] = '拉黑失败';
        	$this->ajaxReturn($result);
		}
	}

	/**
	* 黑名单列表
	*/
	public function blacks(){
		//id
		$user_id = get_user();//I('post.user_id') ? I('post.user_id') : $this->ajaxReturn(is_not('user_id/必须'));
		$page_no = I('post.page_no') ? I('post.page_no') : 1;
		//被拉黑的人
		// $bl_user_id = I('post.bl_user_id') ? I('post.bl_user_id') : $this->ajaxReturn(is_not('bl_user_id/必须'));

		$data = M('black a')
			->page($page_no,10)
			->where(array('user_id'=>$user_id))
			->field('b.username,b.sex,b.star,b.age,b.photo_id,a.bl_user_id,a.id')
			->join('left join zm_user b on a.bl_user_id=b.id')
			->select();

		if ($data) 
		{	
			$result["result"] = true;
			$result['message'] = "查询成功";
			$result['list'] = $data;
			$this->ajaxReturn($result);
		}else
		{
			$result["result"] = false;
        	$result["message"] = '查询失败';
        	$result['list'] = '';
        	$this->ajaxReturn($result);
		}
	}

	/**
	* 取消拉黑
	*/
	public function noBlacklist(){
		$user_id = get_user();

		$bl_user_id = I('post.bl_user_id') ? I('post.bl_user_id') : $this->ajaxReturn(is_not('bl_user_id/必须'));

		$data = M('black')->where(array('user_id'=>$user_id,'bl_user_id'=>array('in',$bl_user_id)))->delete();

		if ($data) 
		{	
			$result["result"] = true;
			$result['message'] = '已经取消了拉黑';
			$result['list'] = $data;
			$this->ajaxReturn($result);
		}else
		{
			$result["result"] = false;
        	$result["message"] = '取消失败';
        	$this->ajaxReturn($result);
		}
	}

	/**
	* 举报
	*/
	public function tip(){
		$user_id = get_user();
		$user = M('user')->where('id='.$user_id)->find();

		if(0 == $user['is_verify']){
			$result["result"] = false;
			$result["message"] = '请先认证';
			return $result;
		}
		$tip_user_id = I('post.tip_user_id') ? I('post.tip_user_id') : $this->ajaxReturn(is_not('tip_user_id/必须'));
		
		$content = I('post.content') ? I('post.content') : $this->ajaxReturn(is_not('content/必须'));

		$type = I('post.type') ? I('post.type') : '活动举报';
		
		$image = I('post.image') ? I('post.image') : $this->ajaxReturn(is_not('image/必须'));

		$image = A('Photo')->updata($image);
		
		$list = array(
			'user_id'    =>$user_id,
			'tip_user_id'=>$tip_user_id,
			'add_time'   =>time(),
			'image'      =>serialize($image),
			'content'    =>$content,
			'type'       =>$type,
			);

		$data = M('tip')->add($list);

		if ($data) 
		{	
			$result["result"] = true;
			$result['message'] = "提交成功";
			$result['list'] = $data;
			$this->ajaxReturn($result);
		}else
		{
			$result["result"] = false;
        	$result["message"] = '举报失败';
        	$this->ajaxReturn($result);
		}
	}

	/**
	* 会员参加的活动
	*/
	public function activity(){

		$user_id = I('post.user_id') ? I('post.user_id') : $this->ajaxReturn(is_not('user_id/必须'));

		$page_no = I('post.page_no') ? I('post.page_no') : 1;

		$lng = I('post.lng') ? I('post.lng') : '116.492302';
		$lat = I('post.type') ? I('post.type') : '39.976315';

		// 活动ID 数组
		$activity_id = M('activity_log')->where('user_id='.$user_id.' AND is_invited=2')->getField('activity_id',true);

		$add_time = M('activity_log')->where('user_id='.$user_id)->field('add_time')->select();

		$map['a.id'] = array('in' ,$activity_id);

		$map['a.is_pay'] = 1;

		$list = M('activity a')->page($page_no,10)
			 	->where($map)
				->field("a.id,a.user_id,a.title,a.cate,a.theme,a.drink,a.start_time,a.sex,a.site,a.right,a.bao_num,a.join_money,a.gift,a.status,a.type,a.lng,a.lat,b.username,b.sex,b.star,b.photo_id")
				->join('left join zm_user b on a.user_id=b.id')
				->order('start_time desc')
				->select();

		foreach ($list as $key => $value) 
		{ 
			$list[$key]['theme'] = explode(',',$value['theme']);
			$list[$key]['gift'] = $value['join_money'] * $value['bao_num'] + $value['gift'];
			$list[$key]['start_time'] = date("Y-m-d H:i:s",$value['start_time']);
			$list[$key]['last_time'] = getIntervalTime($value['add_time']);
			$list[$key]['status_str'] = '报名中';
		}

		$result['photos'] =$photos;
		$result['list']=$list; 

		$this->ajaxReturn($result);
	}


/**
	-------------------------------------------------
	=================================================

	个人资料
*/


	/**
	* 会员修改个人资料2
	*/
	public function update(){
		$user_id = get_user();

		$user_info = I('post.');
		if ($user_info['photo_id']) 
		{
			$image = $user_info['photo_id'];
			A('Face')->error_auths($user_id,'c');
			A('Face')->error_auths($user_id,'a');
			$images = A('Face')->faceTouxiang($image);

			if ($image['status']==110) 
			{	
				A('Face')->error_auth($user_id,'a');
				$this->ajaxReturn(is_not($image['intnum']));
			}else{
				if ($images['intnum']>70) {
					$user_info['photo_id'] = $images['image_url'];
					// $this->ajaxReturn(is_not($images['intnum']));
				}else{
					A('Face')->error_auth($user_id,'c');
					$this->ajaxReturn(is_not('相似度：'.$image['intnum'].'小于70%'));
				}
			}
		}
		$user_info['photo_ok'] = '1';
		$data = M('user')->where(array('id'=>$user_id))->save($user_info);

		if ($data) 
		{	
			$result["result"] = true;
			$result['message'] = '修改成功';
			$result['list'] = $data;
			$this->ajaxReturn($result);
		}else
		{
			$this->ajaxReturn(is_not('修改失败'));
		}
	}

	/**
	* 我的资料1
	*/
	public function myInfo(){
		$user_id = get_user();

		$data = M('user')
			->field("id,username,sex,age,star,introduction,city,job,photo_id,is_verify,label,helloword,body_shape,voice_id,phone,face_token")
			->where('id='.$user_id)->find();

		$data['label'] = explode(",", $data['label']);
		$jump_status = 0;
		
		if (empty($data['phone'])) {
			$jump_status = 3;
		}elseif ($data['is_verify']==0) {
			$jump_status = 4;
		}elseif (!$data['photo_id'] || stristr($user['photo_id'],'wx.qlogo')) 
		{	
			$jump_status = 5;
		}
		$data['jump_status'] = $jump_status;
		$result['status'] = 1;
		$result['self_id'] = $user_id;
		$result['jump_status'] = $jump_status;
		$result['is_verify'] = $data['is_verify'];
		$result['message'] = "请求成功";
		$result['list'] = $data;

		$this->ajaxReturn($result);
	}

	/**
	* 我的活动3
	*/
	public function myActivity(){

		$user_id = get_user();//I('post.user_id') ? I('post.user_id') : $this->ajaxReturn(is_not('user_id/必须'));

		$type = I('post.type') ? I('post.type') : $this->ajaxReturn(is_not('type/必须'));
		$lng = I('post.lng') ? I('post.lng') : '116.492302';
		$lat = I('post.lat') ? I('post.lat') : '39.976315';
		$page_no = I('post.page_no') ? I('post.page_no') : 1;
		// 我发起的 
		if ($type==1) 
		{
			$activity_id = M('activity')->where(array('user_id'=>$user_id,'del'	=> 0))->getField('id',true);

			//$add_time = M('activity')->where('user_id='.$user_id)->field('add_time')->select();
		}

		// 我参与的
		if ($type == 2) 
		{
			$user_id = get_user() ? get_user() : $this->ajaxReturn(is_not('user_id/必须'));
			// 活动ID 数组
			
			$field = 'a.status as join_status,a.is_arrive as join_arrive,a.is_invited,a.is_gift as join_gift,b.id,b.status,b.title,b.cate,b.type,b.lng,b.lat,b.theme,b.start_time,b.add_time,b.site,b.right,b.is_arrive,b.bao_num,b.join_money,b.join_ed,b.gift,c.username,c.sex,c.star,c.photo_id';
			$list = M('activity_log a')->page($page_no,10)
						->field($field)
						->join('left join zm_activity b on a.activity_id=b.id')
						->join('left join zm_user c on b.user_id=c.id')
						->where(array('a.user_id'=>$user_id,'a.is_invited'=>array('in',array(1,2))))
						->order('b.start_time desc')
						->select();
			foreach ($list as $key => $value) 
			{ 
				$list[$key]['theme'] = explode(',',$value['theme']);
				$list[$key]['gift'] = $value['join_money'] * $value['bao_num'] + $value['gift'];
				$list[$key]['start_time'] = date("Y-m-d H:i:s",$value['start_time']);
				$list[$key]['last_time'] = getIntervalTime($value['add_time']);
				$list[$key]['km'] = getdistance($lng,$lat,$value["lng"],$value["lat"]);
				$list[$key]['status_str'] = $this->joinActiviStatusStr($value);
			}

			$result['photos'] =$photos;
			$result['list']=$list; 

			$this->ajaxReturn($result);
			exit;
		}
		
		if(count($activity_id) >=2){
			$map['a.id'] = array('in' ,$activity_id);
		}elseif(count($activity_id) == 1){
			$map['a.id'] = $activity_id[0];
		}else{
			$map['a.id'] = 0;
		}
		$map['is_pay'] = 1;
		$list = M('activity a')->page($page_no,10)
			 	->where($map)
				->field("a.id,a.user_id,a.title,a.cate,a.theme,a.drink,a.bao_ed,a.join_ed,a.is_arrive,a.bao_num,a.start_time,a.add_time,a.sex,a.site,a.right,a.join_money,a.gift,a.is_gift,a.status,a.type,a.lng,a.lat,b.photo_id,b.username,b.sex,b.star")
				->join('left join zm_user b on a.user_id=b.id')
				->order('start_time desc')
				->select();

		foreach ($list as $key => $value) 
		{
			$list[$key]['theme'] = explode(',',$value['theme']);
			$list[$key]['gift'] = $value['join_money'] * $value['bao_num'] + $value['gift'];
			$list[$key]['start_time'] = date("Y-m-d H:i",$value['start_time']);
			$list[$key]['last_time'] = getIntervalTime($value['add_time']);
			$list[$key]['km'] = getdistance($lng,$lat,$value["lng"],$value["lat"]);
			$list[$key]['status_str'] = $this->myActiviStatusStr($value);
		}
		$result['photos'] =$photos;
		$result['list']=$list; 

		$this->ajaxReturn($result);
	}

	private function myActiviStatusStr($activity){
		//分几个时间段，首先是活动还没开始，开始到一个半小时，一个半小时到3个小时，超过三个小时
		$now = time();
		$start_time = $activity['start_time'];
		$str = '';
		if(1 == $activity['status']){
			return '已取消';
		}elseif (11 == $activity['status']) {
			return '爽约';
		}
		if($now < $start_time){
			//活动还没有开始，分三个情况，第一，人数已经报满，第二有人报名了，还没有报满，第三还没有人报名
			if($activity['join_ed'] > 0){
				$str = "待签到";
			}elseif ($activity['bao_ed'] > 0) {
				$str = '待确认';
			}else{
				$str = '报名中';
			}
		}elseif($now-90*60 < $start_time){
			//活动开始了，但还没有超过1个半小时
			if(1 == $activity['is_remark'] || 1 == $activity['is_gift']){
				$str = '已完成';
			}elseif(1 == $activity['is_arrive']){
				$str = '待完成';
			}elseif($activity['join_ed'] > 0){
				$str = '待签到';
			}else{
				$str = '已过期';
			}
		}elseif($now-3*60*60 < $start_time){
			//活动开始一个半小时了，但还没有超过3个小时
			if(1 == $activity['is_gift']){
				$str = '已完成';
			}elseif(1 == $activity['is_arrive']){
				$str = '待完成';
			}elseif($activity['join_ed'] > 0){
				$str = '未完成';
			}else{
				$str = '已过期';
			}
		}else{
			//活动已经结束了，超过了开始时间三个小时
			if(1 == $activity['is_remark'] || 1 == $activity['is_gift']){
				$str = '已完成';
			}elseif(1 == $activity['is_arrive']){
				if(13 == $activity['status']){
					$str = '未完成';
				}else{
					$str = '已完成';
				}
			}
			elseif($activity['join_ed'] > 0){
				$str = '未完成';
			}else{
				$str = '已过期';
			}
		}
		return $str;
	}

	private function joinActiviStatusStr($activity){
		//分几个时间段，首先是活动还没开始，开始到一个半小时，一个半小时到3个小时，超过三个小时
		$now = time();
		$start_time = $activity['start_time'];
		$str = '';
		if(23 == $activity['join_status'] || 1 == $activity['status']){
			return '已取消';
		}
		if (18 == $activity['join_status']) {
			return '未完成';
		}
		if(12 == $activity['join_status']) {
			return '已退出';
		}
		if(1 == $activity['is_invited'] && $start_time < $now){
			return '已过期';
		}
		if($now < $start_time){
			//活动还没有开始，分三个情况，第一，人数已经报满，第二有人报名了，还没有报满，第三还没有人报名
			if(2 == $activity['is_invited']){
				$str = '待签到';
			}else{
				$str = '等待邀约';
			}
		}elseif($now-90*60 < $start_time){
			//活动开始了，但还没有超过1个半小时
			if(1 == $activity['is_invited']){
				$str = '已过期';
			}elseif(1 == $activity['join_gift']){
				$str = '已完成';
			}elseif(1 == $activity['is_arrive']){
				$str = '待完成';
			}else{
				$str = '待签到';
			}
		}elseif($now-3*60*60 < $start_time){
			//活动开始一个半小时了，但还没有超过3个小时
			if(1 == $activity['join_gift']){
				$str = '已完成';
			}elseif(1 == $activity['is_arrive']){
				$str = '待完成';
			}elseif($activity['join_ed'] > 0){
				$str = '未完成';
			}else{
				$str = '已过期';
			}
		}else{
			//活动已经结束了，超过了开始时间三个小时
			if(1 == $activity['join_gift']){
				$str = '已完成';
			}elseif(1 == $activity['is_arrive']){
				$str = '已完成';
			}elseif($activity['join_ed'] > 0){
				$str = '未完成';
			}else{
				$str = '已过期';
			}
		}
		return $str;
	}
	/**
	* 我的活动-删除
	*/
	public function delActivity(){
		$id = I('post.activity_id') ? I('post.activity_id') : $this->ajaxReturn(is_not('activity_id/必须'));
		$type = I('post.type') ? I('post.type') : $this->ajaxReturn(is_not('type/必须'));
		$user_id = get_user();
		// 我发起的 
		if ($type==1) 
		{	
			$ac = M('activity')->field("status,bao_ed,start_time")->where(array('id'=>$id))->find();
			//已经取消的可以删除,没有人报名的可以删除，爽约的可以删除
			if($ac['status'] == 1 || $ac['bao_ed'] == 0 || $ac['status']==11 || $ac['status']== 9){
				$activity_id = M('activity')->where(array('id'=>$id))->save(array('del'=>1));
			}elseif($ac['start_time'] < time() - 3*60*60 || $ac['status'] == 7){
				$activity_id = M('activity')->where(array('id'=>$id))->save(array('del'=>1));
				
			}else{
				$this->ajaxReturn(is_not('不能删除'));
			}
			
		}

		// 我参与的
		if ($type == 2) 
		{
			$acLog = M('activity_log')->where(array('activity_id'=>$id,'user_id'=>$user_id))->find();

			if(in_array($acLog['status'], array(11,14,8))){
				$this->ajaxReturn(is_not('不能删除'));
			}else{
				$activity_id = M('activity_log')->where(array('activity_id'=>$id))->save(array('del'=>1));
			}
			
		}

		$result['status'] = true;
		$result['message'] = "删除成功";
		$this->ajaxReturn($result);

	}

	/**
	* 我的照片4
	*/
	public function myPhotos(){
		$user_id = get_user();

		$photos = M('photos')->field("photo_id,id")->where('user_id='.$user_id)->select();
		$user = M('user')->where('id='.$user_id)->field('is_verify')->getField('is_verify');
		foreach ($photos as $key => $value) {
			$photos[$key]['is_verify']=$user;
		}
		$result['status'] = 1;
		$result['message'] = "请求成功";
		$result['list'] = $photos;

		$this->ajaxReturn($result);
	}

	/**
	* 我的照片添加5
	*/
	public function addPhotos(){
		$user_id = get_user();

		$image = I('post.image') ? I('post.image') : $this->ajaxReturn(is_not('image/必须'));

		$images = A('Photo')->addImg($image);

		$image = array(
			'user_id' => $user_id,
			'photo_id'=> $images,
			);

		$data = M('photos')->add($image);

		if ($data) 
		{	
			$result["result"] = true;
			$result['message'] = "提交成功";
			$result['list'] = $data;
			$result['photo_id'] = $images;
			$this->ajaxReturn($result);
		}else
		{
			$this->ajaxReturn(is_not('上传失败'));
		}
	}


	/**
	* 我的照片删除6
	*/
	public function myDelPhoto(){
		$user_id = get_user();

		$id = I('post.id') ? I('post.id') : $this->ajaxReturn(is_not('图片id必须'));

		$data = M('photos')->where(array('id'=>$id,'user_id'=>$user_id))->delete();

		if ($data) 
		{	
			$result["result"] = true;
			$result['message'] = "提交成功";
			$result['list'] = $data;
			$this->ajaxReturn($result);
		}else
		{
			$this->ajaxReturn(is_not('删除失败'));
		}
	}

	/**
	* 我的红包7
	*/
	public function redMoney(){
		$user_id = get_user();
		$this->judgeRedMoney($user_id);
		$page_no = I('post.page_no') ? I('post.page_no') : 1;
		$data = M('red_money a')->page($page_no,10)
			->where('a.user_id='.$user_id)
			->field('a.id,a.money,a.add_time,a.get_time,a.type,a.status,a.activity_id,a.content,b.start_time,b.theme')
			->join('left join zm_activity b on a.activity_id=b.id')
			->order('add_time desc')
			->select();
		foreach ($data as $k => $v) {
			$data[$k]['get_time'] = date('Y-m-d H:i', $v['get_time']);
			//共享红包没有这些信息
			if($v['type'] != 3){
				//活动开始时间
				$data[$k]['start_time'] = date('Y-m-d H:i', $v['start_time']);
				//活动主题
				$themes = explode(',',$v['theme']);
				$title = ""; $cnt = count($themes);
				if ($themes[0] == 1) {
					if ($cnt == 1) {
						$title = "美食活动";
					}elseif ($cnt == 2) {
						if ($themes[1]==2) {$title = "美食/K歌活动";} else{$title = "美食/酒吧活动";}
					}else{
						$title = "美食/K歌/酒吧活动";
					}
				}elseif ($themes[0] == 2) {
					if ($cnt == 1) {$title = "K歌活动";} else{$title = "K歌/酒吧活动";}
				}else{
					$title = "酒吧活动";
				}
				$data[$k]['activity_title'] = $title; 
			}
			//将红包金额转换成整数
			$data[$k]['money'] = intval($v['money']);
			if ($v['get_time'] <= time() && $v['status'] == 1) {
				$data[$k]['status'] = 2;
				$v['status'] = 2;
				$this->getRedMoney($v['id']);
			}

			if ($v['status'] == -1) {
				$data[$k]['detail'] = "因取消报名退出活动或爽约，该红包已被撤回";
			}elseif ($v['status'] == 0) {
				$data[$k]['status'] = -1;
				$data[$k]['detail'] = "您已被其他活动邀约，该红包已被撤回";
			}elseif ($v['status'] == 1) {
				$data[$k]['detail'] = "红包将于".date('Y/m-d H:i',$v['get_time'])."兑换到钱包";
			}else{
				$data[$k]['detail'] = "红包将于".date('Y/m-d H:i',$v['get_time'])."兑换到钱包";
			}
			if ($v['type'] == 1) {
				$data[$k]['type_word'] = "报名红包"; 
			}elseif($v['type'] == 2){
				$data[$k]['type_word'] = "见面礼红包"; 
			}else{
				$data[$k]['type_word'] = "共享红包"; 
			}
		}
		$list = array();
		foreach ($data as $key => $value) {
			$list[] = $value;
		}
		$sum = M('red_money')->where(array('user_id'=>$user_id,'status'=>1))->getField('sum(money) as money');
		if ($sum) {
			$result['sum'] = $sum;
		}else{
			$result['sum'] = 0;
		}
		if ($data) 
		{	
			$result["result"] = true;
			$result['message'] = "查询成功";
			$result['list'] = $list;
			$this->ajaxReturn($result);
		}else
		{	
			$result["result"] = false;
			$result['message'] = "查询失败";
			$result['list'] = '';
			$this->ajaxReturn($result);
		}
	}
	//将自己所有的红包检查一遍，到期的自动领取
	private function judgeRedMoney($user_id){
		$where = array(
			'user_id' 	=> $user_id,
			'status'	=> 1,
			'get_time'	=> array('lt',time())
		);
		$list = M('red_money')->where($where)->select();
		foreach ($list as $key => $value) {
			$this->getRedMoney($value['id']);
		}
	}
	/**
	* 我的-领取红包8
	*/
	public function redMoneySrue(){
		$user_id = get_user();
		$id =I('post.id') ? I('post.id') : $this->ajaxReturn(is_not('红包id必须'));

		$data = M('red_money')->where(array('id'=>$id,'user_id'=>$user_id))->save(array('status'=>2));
		$ret = M('red_money')->where(array('id'=>$id,'user_id'=>$user_id))->find();

		$type = '101';
		$money = $ret['money'];
		$hongbao = A('Money')->moneyLog($type,$money,$user_id);

		if ($data) 
		{	
			$result["result"] = true;
			$result['message'] = "领取成功";
			$result['list'] = $data;
			$this->ajaxReturn($result);
		}else
		{
			$this->ajaxReturn(is_not('领取失败'));
		}
	}
	//领取红包
	public function getRedMoney($id){
		$redModel = M('red_money');
		$red = $redModel->where('id='.$id)->find();
		if (!$red || $red['status'] == 2) {
			return false;
		}
		$red_rate = M('admin_setting')->where('id=1')->getField('red_rate');
		$redModel->where('id='.$id)->save(array('status'=>2));
		$log_data = array(
			'user_id' 	=> $red['user_id'],
			'money'	 	=> ($red['money']*$red_rate),
			'add_time'	=> $red['get_time'],
			'type'		=> 104,
			'status'	=> 1,
			'activity_id'=> $red['activity_id'],
			'content'	=> '红包金额到账',
			'pay_type'	=> 3	
		);
		M('money_log')->add($log_data);
		M('user')->where('id='.$red['user_id'])->setInc('money',$red['money']);
		return true;
	}
	/**
	* 我的钱包9
	*/
	public function myMoney(){
		$user_id = get_user();
		$data = A('Money')->getMoney($user_id);

		$pwd = M('user')->where('id='.$user_id)->getField('paypwd');
		if (!$pwd) 
		{
			$result['pwd'] = "101";
		}else{
			$result['pwd'] = "ok";
		}
		$frize = M('frize')->where('user_id='.$user_id.' AND status=1')->find();
		if($frize){
			$is_frize = 1;
		}else{
			$is_frize = 0;
		}
		if ($data) 
		{	$result['is_frize'] = $is_frize;
			$result["result"] = true;
			$result['message'] = "查询成功";
			$result['money'] = $data;
			$result['maxmoney'] = M('config')->where(array('key'=>'TI_XIAN_MONEY'))->getField('val');
			$this->ajaxReturn($result);
		}else
		{
			$this->ajaxReturn(is_not('查询失败'));
		}
	}

	/**
	* 我的密码- 设置支付密码10
	*/
	public function paypwd(){
		$user_id = get_user();
		$pwd = I('post.password') ? I('post.password') : $this->ajaxReturn(is_not('密码必须'));
		$pwd1 = I('post.password1') ? I('post.password1') : $this->ajaxReturn(is_not('重复密码必须'));

		if ($pwd !=$pwd1) 
		{
			$this->ajaxReturn(is_not('两次输入的密码不一样'));
		}

		$data = M('user')->where(array('id'=>$user_id))->save(array('paypwd'=>md5($pwd)));

		if ($data) 
		{	
			$result["result"] = true;
			$result['message'] = "设置成功";
			$this->ajaxReturn($result);
		}else
		{
			$this->ajaxReturn(is_not('修改失败'));
		}
	}

	/**
	* 我的密码- 修改支付密码11
	*/
	public function upPaypwd(){
		$user_id = get_user();
		$pwd = I('post.password') ? I('post.password') : $this->ajaxReturn(is_not('密码必须'));

		$pwd1 = I('post.password1') ? I('post.password1') : $this->ajaxReturn(is_not('新密码必须'));

		$pwd2 = I('post.password2') ? I('post.password2') : $this->ajaxReturn(is_not('重复新密码必须'));

		if ($pwd2 !=$pwd1) 
		{
			$this->ajaxReturn(is_not('两次输入的密码不一样'));
		}

		$paypwd = M('user')->where(array('id'=>$user_id))->getField('paypwd');

		if ($paypwd!=md5($pwd)) 
		{
			$this->ajaxReturn(is_not('旧密码错误'));

		}

		$data = M('user')->where(array('id'=>$user_id))->save(array('paypwd'=>md5($pwd1)));

		if ($data ===false) 
		{	
			$this->ajaxReturn(is_not('修改失败'));
		}else
		{
			$result["result"] = true;
			$result['message'] = "修改成功";
			$this->ajaxReturn($result);
		}

	}

	/**
	* 我的密码- 忘记支付密码13
	*/
	public function setPaypwd(){
		$user_id = get_user();
		$pwd = I('post.password') ? I('post.password') : $this->ajaxReturn(is_not('password/密码必须'));
		$pwd1 = I('post.password1') ? I('post.password1') : $this->ajaxReturn(is_not('password1/密码必须'));

		$bank_name =  I('post.bank_name') ? I('post.bank_name') : $this->ajaxReturn(is_not('bank_name必须'));

		$z_name = I('post.z_name') ? I('post.z_name') : $this->ajaxReturn(is_not('z_name必须'));
		$tail_num =  I('post.tail_num') ? I('post.tail_num') : $this->ajaxReturn(is_not('tail_num必须'));

		$list = array(
			'z_name'     =>$z_name,
			'user_id'    =>$user_id,
			'bank_name'  =>$bank_name,
			'tail_num'   =>$tail_num,
			);

		$ret = M('user_bank')->where($list)->find();

		if (time()> (S('ids'.$user_id['gtime'])))
		{
			$data = array(
				'num'=>0,
				'gtime'=>0,
				);
			S('ids'.$user_id,$data,24*60*60);
		}

		if (S('ids'.$user_id)['num']<5)
		{
			$data = array(
				'num'=>S('ids'.$user_id)['num']+1,
				'gtime'=>strtotime(date('Y-m-d',strtotime('+1 day'))),
				);

			S('ids'.$user_id,$data,24*60*60);

		}else
		{
		    $this->ajaxReturn(is_not('很抱歉你5次机会已用完'));
		}

		if(!$ret)
		{
			$this->ajaxReturn(is_not('问题验证失败'));
		}

		if ($pwd !=$pwd1) 
		{
			$this->ajaxReturn(is_not('两次输入的密码不一样'));
		}

		$data = M('user')->where(array('id'=>$user_id))->save(array('paypwd'=>md5($pwd)));

		if ($data === false) 
		{	
			$this->ajaxReturn(is_not('修改失败'));
		}else
		{
			$result["result"] = true;
			$result['message'] = "修改成功";
			$this->ajaxReturn($result);
		}
	}

	/**
	* 我的密码- 设置问题14
	*/
	public function setQuestion(){
		$user_id = get_user();
		$bank_name =I('post.bank_name') ? I('post.bank_name') : $this->ajaxReturn(is_not('bank_name必须'));

		$z_name = I('post.z_name') ? I('post.z_name') : $this->ajaxReturn(is_not('z_name必须'));
		$tail_num = I('post.tail_num') ? I('post.tail_num') : $this->ajaxReturn(is_not('tail_num必须'));
		$tail_nums = I('post.tail_nums') ? I('post.tail_nums') : $this->ajaxReturn(is_not('tail_nums必须'));

		if ($tail_num !=$tail_nums) 
		{
			$this->ajaxReturn(is_not('两次输入的卡号后六位不一样'));
		}

		$list = array(
			'z_name'     =>$z_name,
			'user_id'    =>$user_id,
			'bank_name'  =>$bank_name,
			'tail_num'   =>$tail_num,
			'add_time'   =>time(),
			);

		$data = M('user_bank')->add($list);

		if ($data) 
		{	
			$result["result"]  = true;
			$result['message'] = "提交成功";
			$result['bank_id'] = $data;
			$this->ajaxReturn($result);
		}else
		{
			$this->ajaxReturn(is_not('提交失败'));
		}
	}

	/**
	* 绑定 银行卡19
	*/
	public function setBank(){
		$user_id = get_user();
		$bank_name =I('post.bank_name') ? I('post.bank_name') : $this->ajaxReturn(is_not('bank_name必须'));

		$z_name = I('post.z_name') ? I('post.z_name') : $this->ajaxReturn(is_not('z_name必须'));
		$tail_num = I('post.tail_num') ? I('post.tail_num') : $this->ajaxReturn(is_not('tail_num必须'));
		$bank_num = I('post.bank_num') ? I('post.bank_num') : $this->ajaxReturn(is_not('bank_num必须'));

		$list = array(
			'z_name'     =>$z_name,
			'user_id'    =>$user_id,
			'bank_name'  =>$bank_name,
			'tail_num'   =>$tail_num,
			'bank_num'   =>$bank_num,
			'add_time'   =>time(),
			);

		$data = M('user_bank')->add($list);

		if ($data) 
		{	
			$result["result"]  = true;
			$result['message'] = "提交成功";
			$result['bank_id'] = $data;
			$this->ajaxReturn($result);
		}else
		{
			$this->ajaxReturn(is_not('提交失败'));
		}
	}

	/**
	* 消费记录15
	*/
	public function payLog(){
		$user_id = get_user();
		$page_no = I('post.page_no') ? I('post.page_no') : 1;

		$data = M('money_log a')->page($page_no,10)
			->where(array('a.user_id'=>$user_id))
			->field('a.money,a.add_time,a.type,a.pay_type,a.status,a.activity_id,a.content,b.title,b.theme')
			->join('left join zm_activity b on a.activity_id=b.id')
			->order('a.id desc')
			->select();
		//$data = $list;
		//$i = 0;$len = count($list);
		/*for ($i = 0 ; $i < $len ; $i++) {
			$data[$i] = $list[$len-$i - 1];
		}*/
		foreach ($data as $k => $v) 
		{ 
			$data[$k]['add_time'] = date("Y-m-d H:i:s",$v['add_time']);
			if($v['type'] == 101 || $v['type'] == 102 || $v['type'] == 108){
				$data[$k]['money'] = '-'.$v['money'];
			}else{
				$data[$k]['money'] = '+'.$v['money'];
			}
			if($v['type'] == 101){
				//type 101提现
				$data[$k]['title'] = '余额提现';
			}elseif ($v['type'] == 102) {
				$themes = explode(',',$v['theme']);
				$title = ""; $cnt = count($themes);
				if ($themes[0] == 1) {
					if ($cnt == 1) {
						$title = "发起美食活动";
					}elseif ($cnt == 2) {
						if ($themes[1]==2) {$title = "发起美食&middot;K歌活动";} else{$title = "发起美食/&middot;酒吧活动";}
					}else{
						$title = "发起美食&middot;K歌&middot;酒吧活动";
					}
				}elseif ($themes[0] == 2) {
					if ($cnt == 1) {$title = "发起K歌活动";} else{$title = "发起K歌&middot;酒吧活动";}
				}else{
					$title = "发起酒吧活动";
				}
				//type 102消费
				if($v['pay_type'] == 0){
					//余额
					$data[$k]['title'] = $title.'&nbsp;(余额)';
				}elseif ($v['pay_type'] == 1) {
					//微信
					$data[$k]['title'] = $title.'&nbsp;(微信)';
				}elseif ($v['pay_type'] == 2) {
					//余额+微信
					$data[$k]['title'] = $title.'&nbsp;(余额+微信)';
				}elseif ($v['pay_type'] == 3) {
					//其他
					$data[$k]['title'] = $title;
				}
			}elseif ($v['type'] == 103) {
				//type 103充值
				$data[$k]['title'] = '充值';
			}elseif ($v['type'] == 104) {
				//type 104收到红包
				$data[$k]['title'] = '红包兑换成现金余额';
			}elseif ($v['type'] == 105) {
				//type 105红包退回
				//type 106 活动过期退款
				$themes = explode(',',$v['theme']);
				$title = ""; $cnt = count($themes);
				if ($themes[0] == 1) {
					if ($cnt == 1) {
						$title = "美食活动受邀者爽约退款";
					}elseif ($cnt == 2) {
						if ($themes[1]==2) {
							$title = "美食&middot;K歌活动受邀者爽约退款";
						} else{
							$title = "美食/&middot;酒吧活动受邀者爽约退款";
						}
					}else{
						$title = "美食&middot;K歌&middot;酒吧活动受邀者爽约退款";
					}
				}elseif ($themes[0] == 2) {
					if ($cnt == 1) {$title = "K歌活动受邀者爽约退款";} else{$title = "K歌&middot;酒吧活动受邀者爽约退款";}
				}else{
					$title = "酒吧活动受邀者爽约退款";
				}
				$data[$k]['title'] = $title;
			}elseif($v['type'] == 106){
				//type 106 活动过期退款
				$themes = explode(',',$v['theme']);
				$title = ""; $cnt = count($themes);
				if ($themes[0] == 1) {
					if ($cnt == 1) {
						$title = "美食活动过期退款";
					}elseif ($cnt == 2) {
						if ($themes[1]==2) {
							$title = "美食&middot;K歌活动过期退款";
						} else{
							$title = "美食/&middot;酒吧活动过期退款";
						}
					}else{
						$title = "美食&middot;K歌&middot;酒吧活动过期退款";
					}
				}elseif ($themes[0] == 2) {
					if ($cnt == 1) {$title = "K歌活动过期退款";} else{$title = "K歌&middot;酒吧活动过期退款";}
				}else{
					$title = "酒吧活动过期退款";
				}
				$data[$k]['title'] = $title;
			}elseif($v['type'] == 107){
				//type 107 活动取消退款
				$themes = explode(',',$v['theme']);
				$title = ""; $cnt = count($themes);
				if ($themes[0] == 1) {
					if ($cnt == 1) {
						$title = "美食活动取消退款";
					}elseif ($cnt == 2) {
						if ($themes[1]==2) {
							$title = "美食&middot;K歌活动取消退款";
						} else{
							$title = "美食/&middot;酒吧活动取消退款";
						}
					}else{
						$title = "美食&middot;K歌&middot;酒吧活动取消退款";
					}
				}elseif ($themes[0] == 2) {
					if ($cnt == 1) {$title = "K歌活动取消退款";} else{$title = "K歌&middot;酒吧活动取消退款";}
				}else{
					$title = "酒吧活动取消退款";
				}
				$data[$k]['title'] = $title;
			}elseif($v['type'] == 108){
				$data[$k]['title'] = '支付诚意金';
			}elseif($v['type'] == 109){
				$data[$k]['title'] = '收到诚意金';
			}
		}
		if ($data) 
		{	
			$result["result"]  = true;
			$result['message'] = "查询成功";
			$result['list'] = $data;
			$this->ajaxReturn($result);
		}else
		{
			$result["result"]  = false;
			$result['message'] = "查询失败";
			$result['list'] = '';
			$this->ajaxReturn($result);
		}
	}

	/**
	* 我的二维码21
	*/
	public function userCode(){
		$user_id = get_user();
		
		$data=M('user')->where(array('id'=>$user_id))->getField('code_img');

		if (!$data) 
		{
			$urls = 'http://'.C('INT_COM').'/index.php/Home/Index/user_login?id='.$user_id;

			if ($_SERVER['SERVER_NAME'] != C('INT_COM')) 
			{
				$urls = 'http://'.$_SERVER['SERVER_NAME'].'/next/index.php/Home/Index/user_login?id='.$user_id;
			}
			$data = addCode($urls,$user_id,$img);
			M('user')->where(array('id'=>$user_id))->save(array('code_img'=>$data));
		}
		
		if ($data) 
		{	
			$result["result"]  = true;
			$result['message'] = "查询成功";
			$result['list'] = __ROOT__.$data;
			$this->ajaxReturn($result);
		}else
		{
			$this->ajaxReturn(is_not('查询失败'));
		}
	}

	/**
	* 认证20
	*/
	public function userAuth(){
		$user_id = get_user();

		$image = I('post.image') ? I('post.image') : $this->ajaxReturn(is_not('image/必须'));

		$image = A('Photo')->updata($image);

		$list = array(
			'user_id' => $user_id,
			'add_time'=>time(),
			'image'   =>$image['0'],
			'images'  =>$image['1'],
			);

		$data = M('user_auth')->add($list);

		if ($data) 
		{	
			$result["result"] = true;
			$result['message'] = "提交成功";
			$result['id'] = $data;
			$this->ajaxReturn($result);
		}else
		{
			$this->ajaxReturn(is_not('提交失败'));
		}
	}

	/**
	* 提现22
	*/
	public function backMoney(){
		$user_id = get_user();
		// $alipay = I('post.alipay') ? I('post.alipay') : $this->ajaxReturn(is_not('alipay/必须'));
		// $payname = I('post.payname') ? I('post.payname') : $this->ajaxReturn(is_not('payname/必须'));
		$money = I('post.money') ? I('post.money') : $this->ajaxReturn(is_not('money/必须'));
		// $pwd = I('post.password') ? I('post.password') : $this->ajaxReturn(is_not('请输入支付密码'));
		// $pwds = M('user')->where("id=$user_id")->getField('paypwd');

		// if ($pwds != md5($pwd)) 
		// {
		// 	$this->ajaxReturn(is_not('支付密码错误'));
		// }

		$umoney = A('Money')->getMoney($user_id);

		if ($money > $umoney) 
		{
			$this->ajaxReturn(is_not('最多可提现金额为:'.$umoney));
		}

		$user = M('user')->where(array('id'=>$user_id))->find();

		$list = array(
			'openid'    =>$user['openid'],
			'payname'   =>$user['username'],
			'alipay'    =>$user['phone'],
			'money'     =>$money,
			'add_time'  =>time(),
			'user_id'   =>$user_id,
			);

		$data = M('bank_money')->add($list);

		$results = M('user')->where(array('id'=>$user_id))->setDec('money',$money);

		$list = array(
			'add_time' =>time(),
			'money'    =>$money,
			'type'     =>'101',
			'user_id'  =>$user_id,
			);

		$data = M('money_log')->add($list);

		if ($results) 
		{	
			$result["result"]  = true;
			$result['message'] = "提交成功";
			$result['bank_id'] = $data;
			$this->ajaxReturn($result);
		}else
		{
			$this->ajaxReturn(is_not('提交失败'));
		}
	}

	/**
	* 保存位置
	*/
	public function saveSite(){
		$user_id = get_user();
		$lng = I('post.lng');
		$lat = I('post.lat');

		if($user_id && $lng && $lat)
		{
			$res = M('user')->where('id='.$user_id)->save(array('lng'=>$lng,'lat'=>$lat));
			if($res === false)
			{
				$this->ajaxReturn(array('status'=>0,'message'=>'保存位置失败'));
			}
			$this->ajaxReturn(array('status'=>1,'message'=>'保存位置成功'));
		}
		$this->ajaxReturn(array('status'=>0,'message'=>'参数不足'));
	}
	public function getJobs(){
		$list = M('jobs')->order("first_str")->select();
		if ($list) {
			$this->ajaxReturn(array('status'=>1,'message'=>'请求成功','list'=>$list));
		}
 		$this->ajaxReturn(array('status'=>0,'message'=>'请求失败','list'=>array()));
	}
	public function is_scan(){
		$user_id = get_user();
		$scan = M('scan_time')->where('user_id='.$user_id)->find();
		if($scan){
			if((time() - $scan['scan_time']) < 3600){
				$this->ajaxReturn(array('status'=>1,'message'=>'成功'));
			}else{
				$This->ajaxReturn(array('status'=>0,'message'=>'失败'));
			}
		}else{
			$this->ajaxReturn(array('status'=>0,'失败'));
		}	
	}
}